package com.nbsaas.boot.tenant.data.entity;

import com.nbsaas.boot.code.annotation.*;
import com.nbsaas.boot.jpa.data.entity.AbstractEntity;
import com.nbsaas.boot.jpa.data.entity.User;
import com.nbsaas.boot.rest.enums.StoreState;
import com.nbsaas.boot.rest.filter.Operator;
import lombok.Data;
import org.hibernate.annotations.Comment;

import javax.persistence.*;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;


@org.hibernate.annotations.Table(appliesTo = "saas_sys_tenant", comment = "租户")
@CreateByUser
@ComposeView
@FormAnnotation(title = "租户", model = "租户")
@Data
@Entity
@Table(name = "saas_sys_tenant")
public class Tenant extends AbstractEntity {

    public static Tenant fromId(Long id) {
        Tenant result = new Tenant();
        result.setId(id);
        return result;
    }

    /**
     * 租户名称
     */
    @Comment("租户名称")
    @SearchItem(label = "名称", name = "name")
    @FormField(title = "名称", sortNum = "1", grid = true, col = 12)
    private String name;

    @SearchItem(label = "域名", name = "domain",operator = Operator.eq)
    @Comment("域名")
    @FormField(title = "域名", sortNum = "1", grid = true, col = 12)
    @Column(length = 50)
    private String domain;

    @Comment("租户logo")
    @FormField(title = "logo", sortNum = "1", grid = true, col = 12)
    @Column(length = 50)
    private String logo;

    @Comment("电话")
    @FormField(title = "电话", sortNum = "1", grid = true)
    private String phone;


    @Comment("开始日期")
    @FormField(title = "开始日期", sortNum = "3", grid = true, type = InputType.date)
    private Date beginDate;

    @Comment("到期日期")
    @FormField(title = "到期日期", sortNum = "4", grid = true, type = InputType.date)
    private Date expireDate;


    @FieldName
    @FieldConvert
    @ManyToOne(fetch = FetchType.LAZY)
    private User creator;

    /**
     * 租户介绍
     */
    @Comment("租户介绍")
    @FormField(title = "租户介绍", sortNum = "1", grid = true, type = InputType.textarea)
    private String note;

    @Comment("租户状态")
    private StoreState storeState;
}
